Skip to content

✨ improve hostname detection via getent cmd#5492

Merged
afiune merged 2 commits intomainfrom
afiune/hostname
May 2, 2025
Merged

✨ improve hostname detection via getent cmd#5492
afiune merged 2 commits intomainfrom
afiune/hostname

Conversation

@afiune
Copy link
Copy Markdown
Contributor

@afiune afiune commented May 1, 2025

This change improves hostname detection using getent command for IPv4 and IPv6 for UNIX systems.

The new flow to detect the hostname is:

  1. Keep running hostname -f to retrieve the configured fqdn which has proven to be a reliable way
  2. If the output is localhost, we now run getent hosts 127.0.0.1 (first entry wins)
  3. If IPv4 is not configured or we still get localhost, then we try IPv6 via getent hosts ::1 (like above, first entry wins)

This change improves hostname detection using `getent` command for IPv4
and IPv6 for UNIX systems.

The new flow to detect the hostname is:

1. Keep running `hostname -f` to retrieve the configured fqdn which has
   proven to be a reliable way
2. If the output is `localhost`, we now run `getent hosts 127.0.0.1`
   (first entry wins)
3. If IPv4 is not configured or we still get `localhost`, then we try
   IPv6 via `getent hosts ::1` (like above, first entry wins)

Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2025

Test Results

4 236 tests  +2   4 232 ✅ +2   2m 8s ⏱️ -6s
  402 suites ±0       4 💤 ±0 
   30 files   ±0       0 ❌ ±0 

Results for commit dfa81f6. ± Comparison against base commit 3cb8082.

♻️ This comment has been updated with latest results.

Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
Copy link
Copy Markdown
Contributor

@claytoncasey01 claytoncasey01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@afiune afiune merged commit 24643bd into main May 2, 2025
17 checks passed
@afiune afiune deleted the afiune/hostname branch May 2, 2025 16:00
@github-actions github-actions Bot locked and limited conversation to collaborators May 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants